package cn.wolfcode.qo;


import java.util.List;


import lombok.Getter;

@Getter
public class PageResult<T> {

	//两个用户输入
	private int currentPage;    //当前页
	private int pageSize;		//每页显示的最大条数
	
	//两个sql查询
	private int totalCount;  		//总记录数
	private List<T> data;  		//当前页的数据
	
	//三个计算值
	private int totalPage;  		//总页数
	private int prevPage;   		//上一页
	private int nextPage;   		//下一页


	//用构造器来设置参数
	public PageResult(int currentPage, int pageSize, int totalCount,List<T> result) {

		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.totalCount = totalCount;
		this.data =result;

		if(totalCount <= pageSize){
			this.totalPage = 1;
			this.prevPage = 1;
			this.nextPage = 1;
			return;
		}

		this.totalPage = totalCount % pageSize == 0 ? totalCount/pageSize : totalCount/pageSize+1;
		this.prevPage = currentPage -1 >=1 ? currentPage-1:1;
		this.nextPage = currentPage+1 <= totalPage ? currentPage+1:totalPage;
	}



	
	
	
	
}
